#include "StompedReality/Core/Input/MouseInput.h"
#include <iostream>
namespace StompedReality
{
namespace Input
{
MouseInput::MouseInput( ) {
  this->m_CurrentLeft = 0;
  this->m_PrevLeft = 0;
  this->m_CurrentRight = 0;
  this->m_PrevRight = 0;
}

MouseInput::~MouseInput( ) {
}

StompedReality::Math::Vector2 MouseInput::GetPosition( )
{
  return this->m_CurrentPostion;
}

StompedReality::Math::Vector2 MouseInput::GetPositionDelta( )
{
  return this->m_CurrentPostion - this->m_PrevPostion;
}

bool MouseInput::IsLeftButtonDown( )
{
  return !this->m_PrevLeft && this->m_CurrentLeft;
}

bool MouseInput::IsLeftButtonPressed( )
{
  return this->m_CurrentLeft;
}

bool MouseInput::IsLeftButtonUp( )
{
  return this->m_PrevLeft && !this->m_CurrentLeft;
}

bool MouseInput::IsRightButtonDown( )
{
  return !this->m_PrevRight && this->m_CurrentRight;
}

bool MouseInput::IsRightButtonPressed( )
{
  return this->m_CurrentRight;
}

bool MouseInput::IsRightButtonUp( )
{
  return this->m_PrevRight && !this->m_CurrentRight;
}

void MouseInput::UpdatePosition( StompedReality::Math::Vector2* newPos ) {
  this->m_PrevPostion.SetX( this->m_CurrentPostion.GetX( ));
  this->m_PrevPostion.SetY( this->m_CurrentPostion.GetY( ));
  if (newPos != 0) {
    this->m_CurrentPostion.SetX( newPos->GetX( ));
    this->m_CurrentPostion.SetY( newPos->GetY( ));
  }
}

void MouseInput::UpdateButtons( char* left, char* right ) {
  this->m_PrevLeft = this->m_CurrentLeft;
  this->m_PrevRight = this->m_CurrentRight;
  if ( *left == 1)
  {
    this->m_CurrentLeft = true;
  }
  else if ( *left == 2)
  {
    this->m_CurrentLeft = false;
  }
  if ( *right == 1)
  {
    this->m_CurrentRight = true;
  }
  else if ( *right == 2)
  {
    this->m_CurrentRight = false;
  }
}

}
}